{"ast":null,"code":"import { useRef } from 'react';\nimport warning from \"rc-util/es/warning\";\n/**\n * Keep input cursor in the correct position if possible.\n * Is this necessary since we have `formatter` which may mass the content?\n */\nexport default function useCursor(input, focused) {\n  var selectionRef = useRef(null);\n  function recordCursor() {\n    // Record position\n    try {\n      var start = input.selectionStart,\n        end = input.selectionEnd,\n        value = input.value;\n      var beforeTxt = value.substring(0, start);\n      var afterTxt = value.substring(end);\n      selectionRef.current = {\n        start: start,\n        end: end,\n        value: value,\n        beforeTxt: beforeTxt,\n        afterTxt: afterTxt\n      };\n    } catch (e) {\n      // Fix error in Chrome:\n      // Failed to read the 'selectionStart' property from 'HTMLInputElement'\n      // http://stackoverflow.com/q/21177489/3040605\n    }\n  }\n  /**\n   * Restore logic:\n   *  1. back string same\n   *  2. start string same\n   */\n  function restoreCursor() {\n    if (input && selectionRef.current && focused) {\n      try {\n        var value = input.value;\n        var _selectionRef$current = selectionRef.current,\n          beforeTxt = _selectionRef$current.beforeTxt,\n          afterTxt = _selectionRef$current.afterTxt,\n          start = _selectionRef$current.start;\n        var startPos = value.length;\n        if (value.endsWith(afterTxt)) {\n          startPos = value.length - selectionRef.current.afterTxt.length;\n        } else if (value.startsWith(beforeTxt)) {\n          startPos = beforeTxt.length;\n        } else {\n          var beforeLastChar = beforeTxt[start - 1];\n          var newIndex = value.indexOf(beforeLastChar, start - 1);\n          if (newIndex !== -1) {\n            startPos = newIndex + 1;\n          }\n        }\n        input.setSelectionRange(startPos, startPos);\n      } catch (e) {\n        warning(false, \"Something warning of cursor restore. Please fire issue about this: \".concat(e.message));\n      }\n    }\n  }\n  return [recordCursor, restoreCursor];\n}","map":{"version":3,"names":["useRef","warning","useCursor","input","focused","selectionRef","recordCursor","start","selectionStart","end","selectionEnd","value","beforeTxt","substring","afterTxt","current","e","restoreCursor","_selectionRef$current","startPos","length","endsWith","startsWith","beforeLastChar","newIndex","indexOf","setSelectionRange","concat","message"],"sources":["/data/messenger.client/node_modules/rc-input-number/es/hooks/useCursor.js"],"sourcesContent":["import { useRef } from 'react';\nimport warning from \"rc-util/es/warning\";\n/**\n * Keep input cursor in the correct position if possible.\n * Is this necessary since we have `formatter` which may mass the content?\n */\nexport default function useCursor(input, focused) {\n  var selectionRef = useRef(null);\n  function recordCursor() {\n    // Record position\n    try {\n      var start = input.selectionStart,\n        end = input.selectionEnd,\n        value = input.value;\n      var beforeTxt = value.substring(0, start);\n      var afterTxt = value.substring(end);\n      selectionRef.current = {\n        start: start,\n        end: end,\n        value: value,\n        beforeTxt: beforeTxt,\n        afterTxt: afterTxt\n      };\n    } catch (e) {\n      // Fix error in Chrome:\n      // Failed to read the 'selectionStart' property from 'HTMLInputElement'\n      // http://stackoverflow.com/q/21177489/3040605\n    }\n  }\n  /**\n   * Restore logic:\n   *  1. back string same\n   *  2. start string same\n   */\n  function restoreCursor() {\n    if (input && selectionRef.current && focused) {\n      try {\n        var value = input.value;\n        var _selectionRef$current = selectionRef.current,\n          beforeTxt = _selectionRef$current.beforeTxt,\n          afterTxt = _selectionRef$current.afterTxt,\n          start = _selectionRef$current.start;\n        var startPos = value.length;\n        if (value.endsWith(afterTxt)) {\n          startPos = value.length - selectionRef.current.afterTxt.length;\n        } else if (value.startsWith(beforeTxt)) {\n          startPos = beforeTxt.length;\n        } else {\n          var beforeLastChar = beforeTxt[start - 1];\n          var newIndex = value.indexOf(beforeLastChar, start - 1);\n          if (newIndex !== -1) {\n            startPos = newIndex + 1;\n          }\n        }\n        input.setSelectionRange(startPos, startPos);\n      } catch (e) {\n        warning(false, \"Something warning of cursor restore. Please fire issue about this: \".concat(e.message));\n      }\n    }\n  }\n  return [recordCursor, restoreCursor];\n}"],"mappings":"AAAA,SAASA,MAAM,QAAQ,OAAO;AAC9B,OAAOC,OAAO,MAAM,oBAAoB;AACxC;AACA;AACA;AACA;AACA,eAAe,SAASC,SAAS,CAACC,KAAK,EAAEC,OAAO,EAAE;EAChD,IAAIC,YAAY,GAAGL,MAAM,CAAC,IAAI,CAAC;EAC/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